package com.yanqu.road.entity.grandchild;

public class GrandChildExamOpenTimeParam {

    private String param; // 1;600-5;1320
    private int beginDay; // 星期几
    private long beginTime; // 距离0点的毫秒
    private int endDay;
    private long endTime;

    public GrandChildExamOpenTimeParam(String param) {
        this.param = param;
        String[] split = param.split("-");
        String[] split1 = split[0].split(";");
        String[] split2 = split[1].split(";");
        beginDay = Integer.valueOf(split1[0]);
        beginTime = Long.valueOf(split1[1]) * 60 * 1000;
        endDay = Integer.valueOf(split2[0]);
        endTime = Long.valueOf(split2[1]) * 60 * 1000;
    }

    /**
     * 是否包含这个时间
     */
    public boolean includeTime(int day, long time) {
        if (crossWeekEnd()) {
            if (bigThanBegin(day, time) || smallThanEnd(day, time)) {
                return true;
            }
        } else {
            if (bigThanBegin(day, time) && smallThanEnd(day, time)) {
                return true;
            }
        }
        return false;
    }

    // 跨周日24点
    public boolean crossWeekEnd() {
        return beginDay > endDay || beginDay == endDay && beginTime >= endTime;
    }

    // 比开始大  或等于
    public boolean bigThanBegin(int day, long time) {
        return beginDay < day || beginDay == day && beginTime <= time;
    }

    // 比结束小
    public boolean smallThanEnd(int day, long time) {
        return endDay > day || endDay == day && endTime > time;
    }

    // =========================================================

    public String getParam() {
        return param;
    }

    public void setParam(String param) {
        this.param = param;
    }

    public int getBeginDay() {
        return beginDay;
    }

    public void setBeginDay(int beginDay) {
        this.beginDay = beginDay;
    }

    public long getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(long beginTime) {
        this.beginTime = beginTime;
    }

    public int getEndDay() {
        return endDay;
    }

    public void setEndDay(int endDay) {
        this.endDay = endDay;
    }

    public long getEndTime() {
        return endTime;
    }

    public void setEndTime(long endTime) {
        this.endTime = endTime;
    }
}
